package com.haojiang.mh.service.entity;

import android.text.TextUtils;
import com.haojiang.mh.utils.MUtil;

/**
 * Created by ZapFive on 2019-05-25.
 * <p>
 * wuzhuang@mirahome.me
 */
public class StartEndBean {
    private String start;
    private String end;

    public int getDuration() {
        if (TextUtils.isEmpty(start) || !start.contains(":")) return -1;
        if (TextUtils.isEmpty(end) || !end.contains(":")) return -1;
        int startH = Integer.parseInt(start.substring(0, start.indexOf(":")));
        int startM = Integer.parseInt(start.substring(start.indexOf(":") + 1));
        int endH = Integer.parseInt(end.substring(0, end.indexOf(":")));
        int endM = Integer.parseInt(end.substring(end.indexOf(":") + 1));
        if (endH < startH) endH += 24;
        return (endH - startH) * 3600 + (endM - startM) * 60;
    }

    public int getStart() {
        return MUtil.INSTANCE.getTimeDuration(18, start, "HH:mm");
    }

    public void setStart(String start) {
        this.start = start;
    }

    public int getEnd() {
        return MUtil.INSTANCE.getTimeDuration(18, end, "HH:mm");
    }

    public void setEnd(String end) {
        this.end = end;
    }

    public boolean isNull() {
        return TextUtils.isEmpty(start + end);
    }

    @Override
    public String toString() {
        return "StartEndBean{" +
                "start='" + start + '\'' +
                ", end='" + end + '\'' +
                '}';
    }
}
